package com.lipaluma.xml.mapping;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.BooleanUtils;

import com.lipaluma.field.mapper.AutomaticFieldMapper;
import com.lipaluma.field.mapper.FieldMapper;

@XmlRootElement(name=XmlPathMapping.PATH)
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlPathMapping extends AbstractXmlFieldMapping {
	public static final String PATH = "path";

	@XmlAttribute(required = true)
	private String path;
	@XmlAttribute
	private Class<? extends FieldMapper> with;
	@XmlAttribute(name="mandatory-presence")
	private Boolean presenceMandatory;
	
	public String getPath() {
		return path;
	}
	
	@Override
	public Class<? extends FieldMapper> with() {
		if(with == null)
			return AutomaticFieldMapper.class;
		return with;
	}

	@Override
	public boolean isMultiple() {
		return false;
	}
	
	public boolean isPresenceMandatory() {
		return BooleanUtils.toBoolean(presenceMandatory);
	}
}
